<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns the current in-transaction status of the server</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.pg-trace.html">« pg_trace</a></li>
      <li style="float: right;"><a href="function.pg-tty.html">pg_tty »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.pgsql.html">PostgreSQL 函数</a></li>
    <li>Returns the current in-transaction status of the server</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.pg-transaction-status" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">pg_transaction_status</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">pg_transaction_status</span> &mdash; <span class="dc-title">Returns the current in-transaction status of the server</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.pg-transaction-status-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>pg_transaction_status</strong></span>(<span class="methodparam"><span class="type"><a href="class.pgsql-connection.html" class="type PgSql\Connection">PgSql\Connection</a></span> <code class="parameter">$connection</code></span>): <span class="type">int</span></div>

  <p class="para rdfs-comment">
    Returns the current in-transaction status of the server.
  </p>
  <div class="caution"><strong class="caution">警告</strong>
    <p class="para">
      <span class="function"><strong>pg_transaction_status()</strong></span> will give incorrect results when using
      a PostgreSQL 7.3 server that has the parameter <code class="literal">autocommit</code>
      set to off.  The server-side autocommit feature has been
      deprecated and does not exist in later server versions.
    </p>
  </div>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.pg-transaction-status-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">connection</code></dt>

     <dd>

      <p class="para">An <span class="classname"><a href="class.pgsql-connection.html" class="classname">PgSql\Connection</a></span> instance.</p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pg-transaction-status-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">The status can be <strong><code>PGSQL_TRANSACTION_IDLE</code></strong> (currently idle),
    <strong><code>PGSQL_TRANSACTION_ACTIVE</code></strong> (a command is in progress),
    <strong><code>PGSQL_TRANSACTION_INTRANS</code></strong> (idle, in a valid transaction block),
    or <strong><code>PGSQL_TRANSACTION_INERROR</code></strong> (idle, in a failed transaction block).
    <strong><code>PGSQL_TRANSACTION_UNKNOWN</code></strong> is reported if the connection is bad.
    <strong><code>PGSQL_TRANSACTION_ACTIVE</code></strong> is reported only when a query
    has been sent to the server and not yet completed.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.pg-transaction-status-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
 <td>8.1.0</td>
 <td>
  现在 <code class="parameter">connection</code> 参数接受 <span class="classname"><a href="class.pgsql-connection.html" class="classname">PgSql\Connection</a></span>
  实例，之前接受 <a href="language.types.resource.html" class="link">资源(resource)</a>。
 </td>
</tr>

    </tbody>
   
  </table>

 </div>

 
 <div class="refsect1 examples" id="refsect1-function.pg-transaction-status-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1935">
    <p><strong>示例 #1 <span class="function"><strong>pg_transaction_status()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;$dbconn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"dbname=publisher"</span><span style="color: #007700">)&nbsp;or&nbsp;die(</span><span style="color: #DD0000">"Could&nbsp;not&nbsp;connect"</span><span style="color: #007700">);<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$stat&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_transaction_status</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbconn</span><span style="color: #007700">);<br />&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$stat&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">PGSQL_TRANSACTION_UNKNOWN</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Connection&nbsp;is&nbsp;bad'</span><span style="color: #007700">;<br />&nbsp;&nbsp;}&nbsp;else&nbsp;if&nbsp;(</span><span style="color: #0000BB">$stat&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">PGSQL_TRANSACTION_IDLE</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Connection&nbsp;is&nbsp;currently&nbsp;idle'</span><span style="color: #007700">;<br />&nbsp;&nbsp;}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Connection&nbsp;is&nbsp;in&nbsp;a&nbsp;transaction&nbsp;state'</span><span style="color: #007700">;<br />&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


</div></div></div></body></html>